import api from '../../../utils/api';
import pipe from '../../../assets/js/pipe.js';
import formlist from '../../formList.vue';
import addinfo from '../../addInfo/addInfo.vue';
import qs from 'qs';
var loginName = localStorage.getItem("_loginName");
var marine = localStorage.getItem("_marine");
var roleId = localStorage.getItem("_roleId");
export default {
    components:{
        formlist,//注册组件
        addinfo
    },
    data(){
        return{
            hidden:false,//知识库隐藏
            flag:false,
            pages:1,
            isChecked:false,
            checked: 'workList',
            //默认选中第一项
            selected:"index",
            dialogFormVisible:false,//修改任务弹窗
            dialogFormVisible1:false,//修改任务弹窗
            dialogFormVisible2:false,//编辑工作计划弹窗
            dialogFormVisible3:false,//查看报告弹窗
            dialogFormVisible4:false,//查看报告弹窗
            dialogFormVisible5:false,//查看报告弹窗
            dialogFormVisible6:false,//查看知识库弹窗
            dialogFormVisible7:false,//选中报告类型
            dialogFormVisible8:false,//选中报告类型
            dialogFormVisible9:false,//维护报告填报
            dialogFormVisible10:false,//巡检报告填报
            dialogFormVisible11:false,
            dialogFormVisible12:false,
            dialogFormVisible13:false,
            dialogEngineer:false,
            dialogServicePerson:false,
            dialogDevice:false,
            formLabelWidth1:"60px",
            isShow:[],//执行人显示或隐藏 118
            isShow1:[],
            isShow2:[],//抄送人显示或隐藏 118
            isShow3:[],
            isShow4:[],
            //任务清单
            page1:1,
            isDisabled:true,//分页
            isDisabled1:false,
            total1:0,
            taskData:{
                taskName:'',//任务名
                taskType:[],//任务类型 
                marineBoardCode:[],//海事局
                radarStationCode:[],//雷达站
                taskStatus:[],//任务状态
                auditStatus:[],//审核状态
                startDate:'',//计划开始时间
                endDate:'',//计划结束时间
            },
            query1:'',//v-model 任务类型
            query2:'',//v-model 海事局
            query3:'',//v-model 雷达站
            query4:'',//v-model 任务状态
            query5:'',//v-model 审核状态
            //任务清单列表数据
            taskList:[],
            //查看
            watchList:{
                taskName:'',//任务名称
                taskType:'',//任务类型
                marineBoard:'',//海事局
                radarStation:'',//雷达站
                startDate:'',//预计开始时间
                endDate:"",//预计结束时间
                implementDest:"",//实施对象
                auditPerson:"",//海事局审核人
                taskContent:'',//任务内容
            },

            //工作计划
            workList:[],//工作计划列表
            workData:{
                taskName:'',//任务名
                startDate:'',//计划开始时间
                endDate:'',//计划结束时间
            },
            query6:'',//v-model 任务类型
            query7:'',//v-model 海事局
            query8:'',//v-model 雷达站
            query9:'',//v-model 任务状态
            query10:'',//v-model 审核状态
            personList:[],//选择执行人员
            userList:[],//抄送人员
            //任务清单查看
            checkList:{
                taskName:'',
                taskType:'',
                marineBoard:'',
                radarStation:'',
                implementDest:'',
                planImplementDate:"",
                workload:"",
                taskContent:'',
                id:0,
                presenter:"",
                taskSn:""
            },
            //执行人员安排状态
            personStatus:[],
            getNum:[],
            logName:[],//登录名
            logNames:"",
            taskNum:'',//保存taskSn
            index:0,
            num:0,
            //抄送人员安排
            loginNamess:[],
            loginNames:"",//登陆名
            taskNumber:"",//任务taskSn
            total2:0,
            isDisabled2:true,
            isDisabled3:false,
            page2:1,

            //任务实施
            carryTask:{
                taskName:'',//任务名
                startDate:'',//计划开始时间
                endDate:'',//计划结束时间
            },
            query11:'',//v-model 任务类型
            query12:'',//v-model 海事局
            query13:'',//v-model 雷达站
            query14:'',//v-model 任务状态
            query15:'',//v-model 审核状态
            carryList:[],//任务实施列表
            //查看报告
            checkReport:{
                taskName:"",//任务名称
                reportCode:"",//服务报告编号
                customer:"",//用户
                site:"",//地点
                serviceDate:"",//日期
                servicEngineer:"",//服务工程师
                installation:"",//服务项目
                statusDescript:"",//状态描述
                problemDescript:"",//故障描述
                correctiveAction:"",//处理措施
                furtherActionRequired:"",//是否需要后续工作
                openPoint:"",//遗留问题
                workCompletedOnsite:"",//是否现场完成
                taskGrade:"",//维修评价
                jobDescript:"",//维修评价描述
                gradeCreator:""//评价人
            },
            //el-radio-group
            isNeed: [
                { label: "0", value: "需要" },
                { label: "1", value: "不需要" }
            ],
            isInstallation:[
                { label: "0", value: "安装" },
                { label: "1", value: "调试" },
                { label: "2", value: "远程维修" },
                { label: "3", value: "应急维修" },
                { label: "4", value: "其他" },
            ],
            //查看任务清单
            checkQd:{
                taskName:'',//任务名称
                taskType:'',//任务类型
                marineBoard:'',//海事局
                radarStation:'',//雷达站
                implementDest:'',//实施对象
                planImplementDate:"",//计划日期
                workload:"",//工作量
                taskContent:'',//任务内容
            },
            //知识库文件目录
            treeList:[],
            treeId:"",//选中文件id
            treeSn:"",//taskSn
            fileList:{
                keyword:"",//关键字
                comment:"",//文字说明
            },
            total3:0,//任务实施列表总条数
            isDisabled4:true,//分页
            isDisabled5:false,
            page3:1,
            // 选中报告
            selectReport:[],
            query16:"",
            //新增维修报告
            WxReport:{
                reportCode:'',
                customer:"",
                site:'',
                serviceDate:'',
                servicEngineer:'',
                installation:'0',
                statusDescript:'',
                problemDescript:'',
                correctiveAction:'',
                furtherActionRequired:'0',
                openPoint:'',
                workCompletedOnsite:"0",
                taskGrade:'',
                jobDescript:'',
                gradeCreator:"",
                StringId:"",
                taskSn:""
            },
            defaultProps:{
                children: 'children',
                label: 'text'
            },
            examineData:[],
            userName:[],
            userNames:"",
            userId:[],
            userIds:"",
            //新增维修报告表单rule
            rules:{
                reportCode:[
                    { required: true, message: '不能为空', trigger: 'blur' },
                ],
                customer:[
                    { required: true, message: '请输入用户名称', trigger: 'blur' },
                ],
                site:[
                    { required: true, message: '请输入地点', trigger: 'blur' },
                ],
                serviceDate:[
                    { required: true, message: '请选择时间', trigger: 'blur' },
                ],
                servicEngineer:[
                    { required: true, message: '请选择服务工程师' },
                ],
                statusDescript:[
                    { required: true, message: '请选择状态描述', trigger: 'blur' },
                ],
                problemDescript:[
                    { required: true, message: '请选择故障描述', trigger: 'blur' },
                ],
                correctiveAction:[
                    { required: true, message: '请选择处理措施', trigger: 'blur' },
                ],
                openPoint:[
                    { required: true, message: '请选择遗留问题', trigger: 'blur' },
                ],
                taskGrade:[
                    { required: true, message: '请选择维修评价', trigger: 'blur' },
                ],
                jobDescript:[
                    { required: true, message: '请输入维修评价描述', trigger: 'blur' },
                ],
                gradeCreator:[
                    { required: true, message: '请选择评价人', trigger: 'blur' },
                ]
            },
            //获取报告编码
            getCode:{
                hsjName:'',
                reportCode:"",
                marineCode:'',
                ldzName:"",
                nodeCode:"",
                deviceCode:"",
                auditStatus:""
            },
            getRepCode:{
                reportCode:'',
            },
            //新增维护报告
            addWhReport:{
                reportCode:"",
                radarCode:"",
                serviceDate:"",
                XunjianEngineer:'',
                weather:"",
                serviceDevice:"",
                servicePerson:"",
                serviceContent:"",
                serviceResult:'',
                servicePersonCode:""
            },
            //天气
            weatherOption:[
                {label:"晴",value:"sun"},
                {label:"阴",value:"cloud"},
                {label:"晴转多云",value:"sunToCloud"},
                {label:"雾",value:"fog"},
                {label:"雨",value:"rain"},
                {label:"多云",value:'moreCloud'},
                {label:"冰雹",value:"hail"},
                {label:"其他",value:"other"},
            ],
            //维护报告  雷达站
            whRadar:[],
            // 维护接口人
            sPersonLName:[],
            sPersonLNames:'',
            sPersonId:[],
            sPersonIds:'',
            whDevice:[],
            deviceData:[],//选择设备
            deviceNodeName:"",
            loading:true,
            defaultProp:{
                children: 'children',
                label: 'nodeName'
            },
            //新增巡检报告
            xjReport:{
                reportCode:'',
                radarCode:"",
                serviceEngineer:"",
                serviceContent:"",
                serviceResult:""
            },
            xjList:[],//巡检项目列表
            lastDate:'',
            xjState:[
                {label:"正常",value:"nornal"},
                {label:"不正常",value:"unnornal"},
            ],
            xjReState:"正常",
            xjReState1:"",
        }
  },
  mounted() {
    //任务类型
    this.getXjReportList();
    this.getWxReportList();
    this.getWhReportList();

    this.findTaskType();
    this.findTaskStatus();
    this.findAudioStatus();
    this.addPlandata();
    this.getTask();
    this.getWorkList();
    this.carryTaskList();
    this.SelectWhDevice();
  },
  methods:{
    handleToggleDrawer() {
      this.$refs.drawerLayout.toggle();
    },
    addInfo(){
      this.$router.push('/addinfo');
    },
     //时间格式
    format:function(time){
      var t = new Date(time);
      var year = t.getFullYear();
      var month = (t.getMonth()+1);
      var day = t.getDate();
      var hour = t.getHours();
      var minute = t.getMinutes();
      var second = t.getSeconds();
      if(month<10){
          month = "0"+month;
      }
      if(day<10){
          day = "0"+day;
      }
      if(hour<10){
        hour = "0"+hour;
      }
       if(minute<10){
        minute = "0"+minute;
      }
       if(second<10){
        second = "0"+second;
      }
      if(hour =="00" && minute == "00" && second == "00"){
        return t = year+"-"+month+"-"+day;
      }else{
        return t = year+"-"+month+"-"+day+" "+hour+":"+minute+":"+second;
      }
      
    },

    //任务清单列表 查询
    getTask:async function(){
       
        let data = {
            //页码 条数 登陆用户名 用户所属海事局编号 角色id 任务名 任务类型 海事局 雷达站 任务状态 审核状态 开始时间 结束时间
            params:"page="+this.page1+"&rows="+10+"&loginName="+loginName+"&userMarineBoardCode="+marine+"&roleId="+roleId+"&taskName="
            +this.taskData.taskName+"&taskType="+this.query1+"&marineBoardCode="+this.query2+"&radarStationCode="
            +this.query3+"&taskStatus="+this.query4+"&auditStatus"+this.query5+"&startDate="+this.taskData.startDate+"&endDate="+this.taskData.endDate
        }
        const res = await this.$axios._post(api.findByParams,data);
        if(res.data.success){
            this.dialogFormVisible11 = false;
            this.taskList =  res.data.data;
            this.total1  = res.data.total;
        }
        this.taskData.taskName = '';
        this.query1 = '';
        this.query2 = '';
        this.query3 = '';
        this.query4 = '';
        this.query5 = '';
        this.taskData.startDate = '';
        this.taskData.endDate = '';
    },
    getTaskInfo(){
        this.dialogFormVisible11 = true;
    },
    getWorkInfo(){
        this.dialogFormVisible12 = true;
    },
    getListInfo(){
        this.dialogFormVisible13 = true;
    },
    //任务类型  
    findTaskType:async function(){
        let data = {
            params:"cateCode=TASK_TYPE"
        }
        const res = await this.$axios._post(api.findTaskMsgList,data);
        if(res.data.success){
            this.taskData.taskType = res.data.data;
        }
    },
    //任务状态
    findTaskStatus:async function(){
        let data = {
            params:"cateCode=TASK_STATUS"
        }
        const res = await this.$axios._post(api.findTaskMsgList,data);
        if(res.data.success){
          
            this.taskData.taskStatus = res.data.data;
        }
    },
    //审核状态
    findAudioStatus:async function(){
        let data = {
            params:"cateCode=AUDIT_STATUS"
        }
        const res = await this.$axios._post(api.findTaskMsgList,data);
        if(res.data.success){
            this.taskData.auditStatus = res.data.data;
        }
    },
     //海事局数据
    addPlandata:async function(){
      let data={
        params:"orgTypeCode=HAI_SHI"
      }
      const res = await this.$axios._post(api.findOrg ,data);
      if(res.data.success){ 
        this.taskData.marineBoardCode = res.data.data;
      }
    },
    //选中option e代表选中的值
    selectItem(e){ 
      if(e == '湛江海事局'){
        e = 'ZHAN_JIANG_HAISHIJU';
      }else if(e == '广州海事局'){
        e = 'GUANG_ZHOU_HAISHIJU';
      }else if(e == '汕头海事局'){
        e = 'SHAN_TOU_HAISHIJU';
      }else if(e == '茂名海事局'){
        e = 'MAO_MING_HAISHIJU';
      }else if(e == '惠州海事局'){
        e = 'HUI_ZHOU_HAISHIJU';
      }else if(e == '珠海海事局'){
        e = 'ZHU_HAI_HAISHIJU';
      }else{
        e = 'DONG_GUAN_HAISHIJU';
      }
      this.selectRadar(e);
    },
    //雷达站
    selectRadar:async function(code){
        this.query3='';
        if(this.query2){
            let data = {
                params:"orgCode="+code
            }
            const res = await this.$axios._post(api.findLeida ,data);
            if(res.data.success){
                this.taskData.radarStationCode = res.data.data;
            }
        }else{
            this.$message({
                message:"请先选择海事局",
                type:"warning"
            });
            return;
        }
    },
    //修改未审核任务
    editData(index){
        var startDate = pipe.format(this.taskList[index].planImplementDate);
        var endDate = pipe.addDate(startDate,this.taskList[index].workload);
        this.$store.commit("changData",{
            taskName:this.taskList[index].taskName,
            taskType:this.taskList[index].taskTypeText,
            marineBoard:this.taskList[index].marineBoardCodeText,
            radarStation:this.taskList[index].radarStationCodeText,
            implementDest:this.taskList[index].implementDestText,
            taskContent:this.taskList[index].taskContent,
            presenter:this.taskList[index].presenter,
            startDate:startDate,
            endDate:endDate,
            id:this.taskList[index].id
        })
        this.$router.push('/formList');

    },
    //修改未审核任务  选择海事局
    selectItem1(e){ 
      if(e == '湛江海事局'){
        e = 'ZHAN_JIANG_HAISHIJU';
      }else if(e == '广州海事局'){
        e = 'GUANG_ZHOU_HAISHIJU';
      }else if(e == '汕头海事局'){
        e = 'SHAN_TOU_HAISHIJU';
      }else if(e == '茂名海事局'){
        e = 'MAO_MING_HAISHIJU';
      }else if(e == '惠州海事局'){
        e = 'HUI_ZHOU_HAISHIJU';
      }else if(e == '珠海海事局'){
        e = 'ZHU_HAI_HAISHIJU';
      }else{
        e = 'DONG_GUAN_HAISHIJU';
      }
      this.selectRadar1(e);
    },
     //修改未审核任务 选择雷达站
    selectRadar1:async function(code){
        this.editList.radarStation = '';
        if(this.editList.marineBoard){
            let data = {
                params:"orgCode="+code
            }
            const res = await this.$axios._post(api.findLeida ,data);
            if(res.data.success){
                this.taskData.radarStationCode = res.data.data;
            }
        }else{
            this.$message({
                message:"请先选择海事局",
                type:"warning"
            });
            return;
        }
    },
    //查看任务清单
    async watchTaskList(taskSn,index){
        this.dialogFormVisible4 = true;
        // renqingView
        let data = {
            params:"taskSn="+taskSn
        }
        const res = await this.$axios._post(api.renqingView,data);
        if(res.data.success){
            let response = res.data.data;
            this.watchList.taskName =response.taskName;//任务名称
            this.watchList.taskType = this.taskList[index].taskTypeText;//任务类型
            this.watchList.marineBoard = this.taskList[index].marineBoardCodeText;//海事局
            this.watchList.radarStation = this.taskList[index].radarStationCodeText;//雷达站
            this.watchList.startDate = pipe.formatData(response.planImplementDate);//预计开始时间
            this.watchList.endDate = pipe.formatData(response.planFinishiDate);//预计结束时间
            this.watchList.implementDest = response.deviceString;//实施对象
            this.watchList.auditPerson = response.executorId;//海事局审核人
            this.watchList.taskContent = response.taskContent;//任务内容
        }
    },
     //上一页
     prevPage(){
        this.page1--;
        if(this.page1<=1){
            this.isDisabled=true;
        }
        if(this.page1 < Math.ceil(this.total1/10)){
            this.isDisabled1=false;
        }
        this.getTask();
    },
    //下一页
    nextPage(){
        this.page1++;
        if(this.page1>1){
            this.isDisabled=false;
        }  
        if(this.page1 == Math.ceil(this.total1/10)){
            this.isDisabled1=true;
            this.$message({
                message:"这是最后一页了",
                type:"warning"
            });
        }
        this.getTask();
    },


    //工作计划 列表 查询
    getWorkList:async function(){
        let data = {
             //页码 条数 登陆用户名 用户所属海事局编号 角色id 任务名 任务类型  雷达站 任务状态 审核状态 开始时间 结束时间
            params:"page="+this.page2+"&rows="+10+"&loginName="+loginName+"&userMarineBoardCode="+marine+"&roleId="+roleId+"&taskName="
            +this.taskData.taskName+"&taskType="+this.query6+"&marineBoardCode="+this.query7+"&radarStationCode="+this.query8+"&taskStatus="+this.query9+"&auditStatus"+this.query10+"&startDate="+this.taskData.startDate+"&endDate="+this.taskData.endDate
        }
        const res = await this.$axios._post(api.workFind,data);
        if(res.data.success){
            window.console.log(res);
            this.dialogFormVisible12 = false;
            this.workList = res.data.data;
            this.total2 = res.data.total;
        }
        this.workData.taskName = '';
        this.query6 = '';
        this.query7 = '';
        this.query8 = '';
        this.query9 = '';
        this.query10 = '';
        this.workData.startDate = '';
        this.workData.endDate = '';
    },
     //选中option e代表选中的值
    selectItem2(e){ 
      if(e == '湛江海事局'){
        e = 'ZHAN_JIANG_HAISHIJU';
      }else if(e == '广州海事局'){
        e = 'GUANG_ZHOU_HAISHIJU';
      }else if(e == '汕头海事局'){
        e = 'SHAN_TOU_HAISHIJU';
      }else if(e == '茂名海事局'){
        e = 'MAO_MING_HAISHIJU';
      }else if(e == '惠州海事局'){
        e = 'HUI_ZHOU_HAISHIJU';
      }else if(e == '珠海海事局'){
        e = 'ZHU_HAI_HAISHIJU';
      }else{
        e = 'DONG_GUAN_HAISHIJU';
      }
      this.selectRadar2(e);
    },
    //雷达站
    selectRadar2:async function(code){
        this.query8='';
        if(this.query7){
            let data = {
                params:"orgCode="+code
            }
            const res = await this.$axios._post(api.findLeida ,data);
            if(res.data.success){
                this.taskData.radarStationCode = res.data.data;
            }
        }else{
            this.$message({
                message:"请先选择海事局",
                type:"warning"
            });
            return;
        }
    },
    //执行人员安排
    addPerson:async function(taskSn,index){
        this.num = index;
        this.taskNum = taskSn;
        this.dialogFormVisible1 = true;
        this.personStates(taskSn);
        let data = {
           params:"page="+this.pages+"&rows="+10
        };
        const res = await this.$axios._post(api.addPerson,data);
        if(res.data.success){
            this.personList = res.data.data;
        }
        //添加属性
        var per = this.personList;
        var pes = this.personStatus;
        for(var j = 0;j<per.length;j++){
            per[j].num = [];
            per[j].text = "";
            for(var i=0;i<pes.length;i++){
                if(per[j].loginName == pes[i]){
                    per[j].num.push(1);
                }else{
                    per[j].num.push(0);
                }  
            }
            if(per[j].num.indexOf(1) == -1){
                per[j].text = "空闲";
            }else{
                per[j].text = "已有任务安排";
            }
        }

    },
     //执行人员安排状态
    personStates:async function(taskSn){
        let data = {
            params:'taskSn='+taskSn
        }
        const res = await this.$axios._post(api.findTaskingUser,data);
        if(res.data.success){
            this.personStatus = res.data.data;
        }
    },
    //单元格更改样式
    // cellStyle({row, column, rowIndex, columnIndex}){
    //     if(row.text == "已有任务安排"){
    //         return 'background:	#f1f1f1;'
    //     }
    // },
    //点击任务序列号  查看任务清单
    editPlan:async function(index,taskNum){
        this.dialogFormVisible5 = true;
        this.checkList.taskSn = taskNum;
        let data = {
            params:"taskSn="+taskNum
        };
        const res = await this.$axios._post(api.renqingView,data);
        if(res.data.success){
            this.checkList.workload = res.data.data.workload;
            this.checkList.id = res.data.data.id;
            this.checkList.presenter = res.data.data.presenter;
        }
        this.checkList.taskName = this.workList[index].taskName;
        this.checkList.taskType = this.workList[index].taskTypeText;
        this.checkList.marineBoard = this.workList[index].marineBoardCodeText;
        this.checkList.radarStation = this.workList[index].radarStationCodeText;
        this.checkList.implementDest = this.workList[index].implementDestText;
        this.checkList.planImplementDate = this.format(this.workList[index].planImplementDate);
        this.checkList.taskContent = this.workList[index].taskContent;
    },
    //编辑更新任务清单
    updateRwqds:async function(){  
        var formatData = pipe.formatData(this.checkList.planImplementDate);
        let data = {
        // params:fmtParam(this.checkList)
            //id任务清单 presenter提交人  startdate计划实施时间   taskContent任务内容  taskSn任务序列号  workload工作量
          params:"id="+this.checkList.id+"&presenter="+this.checkList.presenter+"&taskSn="+this.checkList.taskSn+"&taskContent="+this.checkList.taskContent+"&startdate="+formatData+"&workload="+this.checkList.workload
        };
        const res = await this.$axios._post(api.updateRwqds,data);
       if(res.data.success){
           this.getWorkList();
           if(res.data.code == 1){
                this.$message({
                    message:"编辑更新成功",
                    type:"success"
                })
           }
           this.dialogFormVisible5  =false;
        }
    },
    //选择执行人
    selectPerson(selection){
        let t = this
        t.logName = [];
        selection.forEach(element => {
            t.logName.push(element.loginName);
        });
        t.logNames = t.logName.join(",");
    },
    //更新执行人
    updatePerson:async function(){
        let data = {
            //任务序列号  登录名
            params:"taskSn="+this.taskNum+"&loginName="+this.logNames
        }
        const res = await this.$axios._post(api.taskAssignExeutor,data);
        if(res.data.success){
            if(res.data.code == 1){
                this.workList[this.num].executorId = this.logNames;
                this.isShow[this.num] = true;
                this.isShow1[this.num] = false;
                this.dialogFormVisible1 = false;
            }
           
        }
    },
    //抄送人员安排
    findCcUser:async function(taskSn,index){
        this.index = index;
        this.taskNumber = taskSn;
        this.dialogFormVisible = true;
        let data = {
            params:"page="+this.pages+"&rows=10"

        }
        const res = await this.$axios._post(api.findUser,data);
        if(res.data.success){
            this.userList = res.data.data;
        }
    },
    //选择抄送人
    selectUser(selection){
        let t = this
        t.loginNamess = [];
        selection.forEach(element => {
            t.loginNamess.push(element.loginName);
        });
        t.loginNames = t.loginNamess.join(",");
        window.console.log(t.loginNames);
    },
    //更新抄送人
    updateUser:async function(){
        let data = {
            params:"taskSn="+this.taskNumber+"&loginName="+this.loginNames
        }
        const res = await this.$axios._post(api.taskAssignCcUser,data);
        if(res.data.success){
            if(res.data.code == 1){
                this.workList[this.index].ccUserId = this.loginNames;
                this.isShow2[this.index] = true;
                this.isShow3[this.index] = false;
                this.dialogFormVisible = false;
            }
            
        }
    },
    //操作  执行计划
    async carryPlan(taskSn,executorId,ccUserId){
        if(executorId !== undefined && ccUserId !== undefined){
            let data = {
                params:"taskSn="+taskSn
            }
            const res = await this.$axios._post(api.taskPlay,data);
            if(res.data.success){
                this.$message({
                    message:res.data.msg,
                    type:"success"
                });
                this.getWorkList();
            }
        }else if(executorId == undefined || ccUserId == undefined){
            this.$message({
                message:"请先分配执行人员",
                type:"warning"
            });
            return;
        }
        //taskPlay
       
    },
    //分页
    prev(){
        this.page2--;
        if(this.page2<=1){
            this.isDisabled2=true;
        }
        if(this.page2 < Math.ceil(this.total2/10)){
            this.isDisabled3=false;
        }
        this.getWorkList();
    },
    next(){
        this.page2++;
        if(this.page2>1){
            this.isDisabled2=false;
        }  
        if(this.page2 == Math.ceil(this.total3/10)){
            this.isDisabled3=true;
            this.$message({
                message:"这是最后一页了",
                type:"warning"
            });
        }
        this.getWorkList();
    },


    //任务实施
    selectItem3(e){ 
      if(e == '湛江海事局'){
        e = 'ZHAN_JIANG_HAISHIJU';
      }else if(e == '广州海事局'){
        e = 'GUANG_ZHOU_HAISHIJU';
      }else if(e == '汕头海事局'){
        e = 'SHAN_TOU_HAISHIJU';
      }else if(e == '茂名海事局'){
        e = 'MAO_MING_HAISHIJU';
      }else if(e == '惠州海事局'){
        e = 'HUI_ZHOU_HAISHIJU';
      }else if(e == '珠海海事局'){
        e = 'ZHU_HAI_HAISHIJU';
      }else{
        e = 'DONG_GUAN_HAISHIJU';
      }
      this.selectRadar3(e);
    },
    //雷达站
    selectRadar3:async function(code){
        this.query13='';
        if(this.query12){
            let data = {
                params:"orgCode="+code
            }
            const res = await this.$axios._post(api.findLeida ,data);
            if(res.data.success){
                this.taskData.radarStationCode = res.data.data;
            }
        }else{
            this.$message({
                message:"请先选择海事局",
                type:"warning"
            });
            return;
        }
    },
    //任务实施列表
    carryTaskList:async function(){
        if(roleId == 'xmjl'){
            this.hidden = true;
        }
        if(roleId =='jsgchs'){
            this.flag = true;
        }
        let data = {
              //页码 条数 登陆用户名 用户所属海事局编号 角色id 任务名 任务类型  雷达站 任务状态 审核状态 开始时间 结束时间
            params:"page="+this.page3+"&rows="+10+"&loginName="+loginName+"&userMarineBoardCode="+marine+"&roleId="+roleId+"&taskName="
            +this.carryTask.taskName+"&taskType="+this.query11+"&marineBoardCode="+this.query12+"&radarStationCode="+this.query13+"&taskStatus="
            +this.query14+"&auditStatus"+this.query15+"&startDate="+this.carryTask.startDate+"&endDate="+this.carryTask.endDate
        }
        const res = await this.$axios._post(api.carryTask,data);
        if(res.data.success){
            this.dialogFormVisible13 = false;
            this.total3 = res.data.total;
            this.carryList = res.data.data;
            // window.console.log(res);
        }
        this.carryTask.taskName = '';
        this.query11 = '';
        this.query12 = '';
        this.query13 = '';
        this.query14 = '';
        this.query15 = '';
        this.carryTask.startDate = '';
        this.carryTask.endDate = '';
    },
    //查看报告
    watchReport:async function(taskSn,taskType,index){
        this.dialogFormVisible3 = true;
        let data = {
            params:"taskSn="+taskSn+"&taskType="+taskType
        }
        const res = await this.$axios._post(api.getReport,data);
        if(res.data.success){
            this.checkReport.reportCode = res.data.data[index].reportCode;//服务报告编号
            this.checkReport.customer = res.data.data[index].customer;//用户
            this.checkReport.site = res.data.data[index].site;//地点
            this.checkReport.serviceDate = res.data.data[index].serviceDate;//日期
            this.checkReport.servicEngineer = res.data.data[index].servicEngineer;//服务工程师
            this.checkReport.installation = res.data.data[index].installation;//服务项目
            this.checkReport.statusDescript = res.data.data[index].statusDescript;//状态描述
            this.checkReport.problemDescript = res.data.data[index].problemDescript;//故障描述
            this.checkReport.correctiveAction = res.data.data[index].correctiveAction;//处理措施
            this.checkReport.furtherActionRequired = res.data.data[index].furtherActionRequired;//是否需要后续工作
            this.checkReport.openPoint = res.data.data[index].openPoint;//遗留问题
            this.checkReport.workCompletedOnsite = res.data.data[index].workCompletedOnsite;//是否现场完成
            //维修评价
            if(res.data.data[index].taskGrade == 'YOU_XIU'){
                this.checkReport.taskGrade = '优秀';
            }
            this.checkReport.jobDescript = res.data.data[index].jobDescript;//维修评价描述
            this.checkReport.gradeCreator = res.data.data[index].gradeCreator;//评价人
            window.console.log(this.checkReport);
        }
    },
    //任务清单查看
    checkQdan:async function(index,taskSn){
        this.dialogFormVisible2 = true;
       let data = {
           params:"taskSn="+taskSn
       }
       const res = await this.$axios._post(api.checkReport,data);
       if(res.data.success){
           this.checkQd = res.data.data;
           var taskType = this.checkQd.taskType;
           if( taskType == 'XUN_JIAN'){
               this.checkQd.taskTypeText = '巡检';
           }else if( taskType == 'WEI_XIU'){
               this.checkQd.taskTypeText = '维修';
           }else if( taskType == 'WEI_HU' ){
               this.checkQd.taskTypeText = '维护';
           }else {
               this.checkQd.taskTypeText = '应急';
           }
           this.checkQd.taskType = this.checkQd.taskTypeText;//任务类型
           this.checkQd.marineBoard = this.carryList[index].hsjName;//海事局
           this.checkQd.radarStation = this.carryList[index].ldzName;//雷达站
           this.checkQd.implementDest = this.carryList[index].deviceName;//实施对象
         
       }
       window.console.log( this.checkQd)
    },
    //移植知识库
    async getDevice(){
        this.dialogFormVisible6 = true;
        let data = {
            params:""
        }
        const res = await this.$axios._post(api.fileTree,data);
        if(res.data.success){
           this.treeList = res.data.data;
        }
    },
    //勾选知识库 checkbox
    getChecked(e){
       this.treeSn = e;
    },
      //选中知识库文件
    handleNodeClick(data){
        this.treeId = data.id;
    },
    //保存知识库文件
    async saveTreeInfo(){
        var that = this;
        if(this.treeSn == ''){
            this.$message({
                message:"请先选中某一列表",
                type:"warning"
            })
            return;
        }
        if(this.treeId !== '' && this.fileList.keyword !== '' && this.fileList.comment !== ''){
            let data ={
                //任务序列号  登陆名  目录id  关键字  文件说明
                params:"taskSn="+this.treeSn+"&loginName="+loginName+"&pid="+this.treeId+"&keyword="+this.fileList.keyword+"&comment="+this.fileList.comment
            }
            this.$axios._post(api.moveFile,data).then(res=>{
                if(res.data.success){
                    that.dialogFormVisible6 = false;
                    that.$message.success({
                        message:"已移至到知识库"
                    })
                }
            }).catch(err=>{
                that.$message.warning(err && err.message);
            })
        }else{
            this.$message({
                message:"请填写完整信息",
                type:"warning"
            })
            return;
        }
        this.fileList.keyword = '';
        this.fileList.comment = '';
    },
    getPrevPage(){
        this.page3--;
        if(this.page3<=1){
            this.isDisabled4=true;
        }
        if(this.page3 < Math.ceil(this.total3/10)){
            this.isDisabled5=false;
        }
        this.carryTaskList();
    },
    getNextPage(){
        this.page3++;
        if(this.page3>1){
            this.isDisabled4=false;
        }  
        if(this.page3 == Math.ceil(this.total3/10)){
            this.isDisabled5=true;
            this.$message({
                message:"这是最后一页了",
                type:"warning"
            });
        }
        this.carryTaskList();
    },
    //新增报告
    async addReport(taskSn,hsjName,marineCode,ldzName,nodeCode,auditStatus){
        this.dialogFormVisible7 = true;
        this.WxReport.taskSn = taskSn;
        this.addWhReport.taskSn = taskSn;
        this.getCode.hsjName = hsjName;
        this.getCode.marineCode = marineCode;
        this.getCode.nodeCode = nodeCode;
        this.xjReport.radarCode = ldzName+'雷达站';
        this.getCode.auditStatus = auditStatus;
        let data = {
            params:"cateCode=TASK_TYPE"
        }
        const res = await this.$axios._post(api.findTaskMsgList,data);
        if(res.data.success){
            var result = res.data.data;
            for(let i=0;i<result.length;i++){
                if(result[i].code == "XUN_JIAN"){
                    result[i].name = '巡检报告'
                }else if(result[i].code == "WEI_XIU"){
                    result[i].name = '维修报告'
                }else if(result[i].code == "WEI_HU"){
                    result[i].name = '维护报告'
                }else{
                    result[i].name = '应急报告'
                }
            }
        }
       this.selectReport = res.data.data;
    },
    //保存选中报告类型
    async saveResult(){
        this.dialogFormVisible7 = false;
        this.getRCode();
        this.getRadar();
        this.getXjList();
        if(this.query16 == 'XUN_JIAN'){
            this.dialogFormVisible10 = true;
        }else if(this.query16 == 'WEI_XIU'){
            this.dialogFormVisible8 = true;
        }else if(this.query16 == 'WEI_HU'){
            this.dialogFormVisible9 = true;  
        }else{
            return
        }
    },
    getWxEngineer(){
        this.dialogFormVisible8 = false;
        this.getEngineer();
    },
    getWhEngineer(){
        this.dialogFormVisible9 = false;
        this.getEngineer();
    },
    getWhWeihuren(){
        this.dialogFormVisible9 = false;
        this.getWeihuren();
    },
     //审核人名单
    getEngineer:async function(){
        this.dialogEngineer = true;
        let data = {
            params:"page="+this.pages+"&rows="+10
        }
        const res = await this.$axios._post(api.findHsjUser,data);
        if(res.data.success){
            this.examineData = res.data.data;
        }
    },
    getWeihuren:async function(){
        this.dialogServicePerson = true;
        let data = {
            params:"page="+this.pages+"&rows="+10
        }
        const res = await this.$axios._post(api.findHsjUser,data);
        if(res.data.success){
            this.examineData = res.data.data;
        }
    },
    //取消选择审核人
    cancleWxResult(){
        this.dialogEngineer= false;
        this.dialogFormVisible8 = true;
    },
    selectData(selection){
        let t = this
        t.userName = [];
        t.userId = [];
        selection.forEach(element => {
            t.userName.push(element.userName);
            t.userId.push(element.id);
        });
        t.userNames = t.userName.join(",");
        t.userIds = t.userId.join(",");
    },
    selectServicePerson(selection){
        let t = this
        t.sPersonLName = [];
        t.sPersonId = [];
        selection.forEach(element => {
            t.sPersonLName.push(element.userName);
            t.sPersonId.push(element.id);
        });
        t.sPersonLNames = t.sPersonLName.join(",");
        t.sPersonIds = t.sPersonId.join(",");
    },
    saveExamineData(){
        this.dialogEngineer = false;
        this.dialogServicePerson = false;
        if(this.query16 == 'WEI_XIU'){
            this.dialogFormVisible8 = true;
            this.WxReport.servicEngineer = this.userNames;
        }else if(this.query16 == 'WEI_HU'){
            this.dialogFormVisible9 = true;
            this.addWhReport.serviceEngineer = this.userNames;
            this.addWhReport.servicePerson = this.sPersonLNames;
        }
        
        
        this.userName = [];
        this.userId = [];
    },
    selectFurther(e){
        this.WxReport.furtherActionRequired = e;
    },
    selectWord(e){
        this.WxReport.workCompletedOnsite = e;
    },
    selectInstal(e){
        this.WxReport.installation = e;
    },
    callbackWx(result){
        this.WxReport.reportCode = result.data;
    },
    callbackWh(result){
        this.addWhReport.reportCode = result.data;
    },
    callbackXj(result){
        this.xjReport.reportCode = result.data;
    },
    //获取报告编号
    async getRCode(){
        // callback
        let data = {
            //海事局名称  报告类型
            params:'hsjName='+this.getCode.hsjName+"&reportType="+this.query16
        }
        const res = await this.$axios._post(api.getReportCode,data);
        if(res.data.success){
            this.callbackWx(res.data);
            this.callbackWh(res.data);
            this.callbackXj(res.data);
        }
    },
    saveWxResult(formName){
        var weixiuParams ={
            reportCode:this.WxReport.reportCode,
            correctiveAction:this.WxReport.correctiveAction,
            furtherActionRequired:this.WxReport.furtherActionRequired,
            customer:this.WxReport.customer,
            problemDescript:this.WxReport.problemDescript,
            openPoint:this.WxReport.openPoint,
            serviceDate:pipe.formatData(this.WxReport.serviceDate),
            servicEngineer:this.WxReport.servicEngineer,
            servicEngineerText:this.userIds,
            site:this.WxReport.site,
            statusDescript:this.WxReport.statusDescript,
            taskSn:this.WxReport.taskSn,
            workCompletedOnsite:this.WxReport.workCompletedOnsite,
            StringId:this.WxReport.StringId,
            gradeCreator:this.WxReport.gradeCreator,
            gradeDescript:this.WxReport.jobDescript,
            taskGrade:this.WxReport.taskGrade,
            fuwuxiangmu:'0',
        } 
        this.$refs[formName].validate((valid) => {
            if (valid) {
                let data = {
                    params:qs.stringify(weixiuParams)
                }
                this.$axios._post(api.addWeixiubaogao,data).then(res=>{
                    if(res.data.success){
                        // this.flag = true;
                        // this.watchReports()
                        this.$message.success({
                            message:res.data.msg
                        });
                        this.WxReport.customer = '';
                        this.WxReport.site = '';
                        this.WxReport.serviceDate = '';
                        this.WxReport.servicEngineer = '';
                        this.WxReport.statusDescript = '';
                        this.WxReport.problemDescript = '';
                        this.WxReport.openPoint = '';
                        this.WxReport.taskGrade = '';
                        this.WxReport.jobDescript = '';
                        this.WxReport.gradeCreator = '';
                        this.WxReport.taskGrade = '';
                        this.WxReport.correctiveAction = '';
                    }
                });
               
            } else {
              return false;
            }
        });
        
    },
    async getRadar(){
        let data = {
            params:"orgCode="+this.getCode.marineCode
        }
        const res = await this.$axios._post(api.findLeida,data);
        if(res.data.success){
            this.whRadar = res.data.data;
        }
    },
    selectDevice(){
        this.dialogDevice = true;
        // this.SelectWhDevice();
    },
    // 维护设备数据列表
    async SelectWhDevice(){
        this.deviceData = [];
        let data = {
            params:"roleId="+roleId
        }
        const res = await this.$axios._post(api.initDeviceTree,data);
        if(res.data.success){
            this.forData(res.data.data);
            this.loading = false;
        }
    },
    forData(res){
        let obj = res[257];//广东省 i = 257
        obj.children = [];
        this.deviceData.push(obj);
        res.splice(257,1);
        orderData(this.deviceData);
        function orderData(newRes){
            for(let i=0;i<newRes.length;i++){
                for(let j=0;j<res.length;j++){
                    if(newRes[i].nodeCode == res[j].parentCode){
                        var obj1 = res[j];
                        obj1.children = [];
                        newRes[i].children.push(obj1);
                        res.splice(j,1);
                        j--;
                    }
                }
                orderData(newRes[i].children);
            }
        }
    },
    //选择维护设备
    handleDevice(data){
        this.addWhReport.serviceDevice = data.nodeName
        this.getCode.deviceCode = data.deviceTypeCode
    },
    //保存维修设备
    saveDeviceList(){
        this.dialogDevice = false;
    },
    //新增维护报告
    async saveWhResult(){
        var weihuParams ={         
            deviceCode:this.getCode.deviceCode,//维护设备code
            reportCode:this.addWhReport.reportCode,//报告编号
            radarStationCode:this.addWhReport.radarCode,//	雷达站CODE
            jobTime:pipe.formatData(this.addWhReport.serviceDate),//维护保养时间
            person:this.userIds,	//巡检维护工程师 code
            personText:this.addWhReport.servicePerson,//巡检维护工程师
            jobContent:this.addWhReport.serviceContent,//维护内容
            jobResult:this.addWhReport.serviceResult,//维护结果
            jobPerson:this.sPersonIds,//维护人code
            jobPersonText:this.addWhReport.serviceEngineer,//维护人
            taskSn:this.addWhReport.taskSn,//相关任务系列号
            weather:this.addWhReport.weather,//天气情况
            StringId:this.addWhReport.StringId,//任务id
            // fuwuxiangmu:'0',
        };
        let data = {
            params:qs.stringify(weihuParams)
        }
        const res = await this.$axios._post(api.addWeihubaogao,data);
        if(res.data.success){
            this.$message.success({
                message:"添加成功"
            });
            this.dialogFormVisible9 = false;
        }
    },
    //巡检项目列表
    // xjList
    async getXjList(){
        window.console.log(this.getCode.nodeCode);
       
            let data = {
                params:"marineStationCode="+this.getCode.nodeCode
            }
            const res = await this.$axios._post(api.xunjianList,data);
            if(res.data.success){
                window.console.log('列表',res);
                this.xjList = res.data.data;
                // for(var i=0;i<this.xjList.length;i++){
                //     if(this.xjList[i].parentId){
                       
                //     }
                // }
            }
        
        
    },
    //getReport
    async watchReports(){
        let data = {
            params:'taskSn=20181015002'
        }
        const res = await this.$axios._post(api.getReport,data);
        if(res.data.success){
            window.console.log('b',res);
        }
    },
    //报告列表
    async getXjReportList(taskSn){
        let data = {
            params:"taskSn="+taskSn+"&taskType=XUN_JIAN"
        }
        const res = await this.$axios._post(api.getReportList,data);
        if(res.data.success){
          
          //  window.console.log('a',res);
        }
    },
    async getWxReportList(taskSn){
        let data = {
            params:"taskSn="+taskSn+"&taskType=WEI_XIU"
        }
        const res = await this.$axios._post(api.getReportList,data);
        if(res.data.success){
         //   window.console.log('a',res);
        }
    },
    async getWhReportList(taskSn){
        let data = {
            params:"taskSn="+taskSn+"&taskType=WEI_HU"
        }
        const res = await this.$axios._post(api.getReportList,data);
        if(res.data.success){
         //   window.console.log('a',res);
        }
    }
  }
}